import java.util.Comparator;
import java.util.PriorityQueue;

public class demo1 {
    public static int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer>queue=new PriorityQueue<>(Comparator.reverseOrder());
        for(int i=0;i<stones.length;i++){
            queue.offer(stones[i]);
        }
        while (queue.size()>1){
            int temp1=queue.poll();
            int temp2=queue.poll();
            queue.offer(Math.abs(temp1-temp2));
        }
        return queue.peek();
    }

    public static void main(String[] args) {
        int []arr=new int[]{1,2,3};
        System.out.println(demo1.lastStoneWeight(arr));
    }
}
